﻿<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;
using mp.message.util;

public class Handler : IHttpHandler {
    public void ProcessRequest(HttpContext context)
    {
        //Valid(context);
        context.Request.ContentEncoding = System.Text.Encoding.UTF8;
        context.Response.ContentEncoding = System.Text.Encoding.UTF8;
        
        //返回给用户的XML格式串
        string respXmlStr=CoreService.ProcessRequest(context.Request);
        context.Response.Write(respXmlStr);
    }
    public bool IsReusable {
        get {
            return false;
        }
    }
    /// <summary>
    /// 校验接入页面，校验完成后可以注释掉
    /// </summary>
    /// <param name="context"></param>
    public void Valid(HttpContext context)
    {
        // 微信加密签名 
        string signature = context.Request.QueryString["signature"].ToString();
        // 时间戳 
        string timestamp = context.Request.QueryString["timestamp"].ToString();
        // 随机数 
        string nonce = context.Request.QueryString["nonce"].ToString();
        // 随机字符串 
        string echoStr = context.Request.QueryString["echoStr"].ToString();
        if (SignUtil.CheckSignature(signature, timestamp, nonce))
        {
            if (!string.IsNullOrEmpty(echoStr))
            {
                context.Response.Write(echoStr);
                context.Response.End();
            }
        }
    }
}